from django.db import models
from django.contrib.auth.models import User


class Notification(models.Model):
    """通知"""
    NOTIFICATION_TYPE_CHOICES = [
        ('task', '任务'),
        ('meeting', '会议'),
        ('approval', '审批'),
        ('event', '活动'),
    ]
    
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='notifications', verbose_name='接收者', db_comment='接收者ID')
    title = models.CharField(max_length=200, verbose_name='通知标题', db_comment='通知标题')
    content = models.TextField(verbose_name='通知内容', db_comment='通知内容')
    notification_type = models.CharField(max_length=20, choices=NOTIFICATION_TYPE_CHOICES, verbose_name='类型', db_comment='类型:task任务,meeting会议,approval审批,event活动')
    related_object_type = models.CharField(max_length=50, null=True, blank=True, verbose_name='关联对象类型', db_comment='关联对象类型')
    related_object_id = models.IntegerField(null=True, blank=True, verbose_name='关联对象ID', db_comment='关联对象ID')
    is_read = models.BooleanField(default=False, verbose_name='是否已读', db_comment='是否已读')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间', db_comment='创建时间')

    class Meta:
        verbose_name = '通知'
        verbose_name_plural = '通知'
        db_table = 'zhahuo_notification'
        db_table_comment = '通知信息表'
        ordering = ['-created_at']

    def __str__(self):
        return f'{self.user.username} - {self.title}'
